import React, { useSyncExternalStore } from 'react';
import store from "./store";

export default function UseSyncExternalStoreDemo(maxAge) {

  const num = useSyncExternalStore(store.subscribe, () => store.getState().count);

  function add(){
    store.dispatch({
      type:"ADD",
      payload:2
    })
  }

  return (
    <div>
      <h1>useSyncExternalStore示例</h1>
      <p>num:{num}</p>
      <input type="button" value="加法" onClick={add} />
    </div>
  )
}